Note. These notes are mainly a record of what we discussed and are not a substitute for attending the lectures and reading books! If anything is unclear/wrong, let me know and I will update the notes.
usingPlotsusingLaTeXStringsusingPolynomialsusingPrettyTablesfunctionf₁( x )return x +rand()endfunctionf₂( x )return1/( 1+exp( x ) );endfunctionf₃( x, α =25 )return1/( 1+ α*x^2 );endf₄ = t ->max(0, @. 1-abs(t) )
#11 (generic function with 1 method)
7.1 Previously…..
Chapter 1: Floating Point Numbers
Chapter 2: Solving Nonlinear Equations in 1d
7.2 Chapter 3: Interpolation
Before: solution was \xi \in \mathbb R, represented numerically as a floating point number
Now: want to represent a function f : [a,b] \to \mathbb R numerically (discretisation problem)
Interpolation Problem:
Suppose that X = \{ x_0 < \cdots < x_n \} is a set of distinct interpolation nodes, 0 \leq m_0, \dots, m_n \leq m, and f is an m times differentiable function.
For x_0 < \cdots < x_n (nodes) and a function f defined on X = \{x_0,\dots,x_n\}, there exists a unique polynomial interpolantI_Xf of degree at most n such that I_Xf(x_j) = f(x_j) for all j=0,\dots,n.
In the following, we will write \mathcal P_n := \{p(x) = \sum_{j=0}^n a_j x^j \colon a_0, \dots,a_n \in \mathbb R\} for the set of polynomials of degree at most n.
N =10X =range( -1, 1, N+1)Y =f₁.(X)scatter( X, Y, primary =false, markersize =5 )
p =fit( X, Y )plot( p , xlims=(-1.05,1.05), legend =false, lw =3)scatter!( X, Y, primary =false, markersize =5, color="green")
therefore satisfies p(x_k) = \sum_{j=0}^n \ell_j(x_k) f(x_j) = \sum_{j=0}^n \delta_{jk} f(x_j) = f(x_k) for each k=0,...,n. That is p solves the Lagrange interpolation problem.
Uniqueness: suppose that q \in \mathcal P_n interpolates f at X. Then, p - q has zeros at each x_j, we have that x - x_j divides p-q: that is p(x) - q(x) = \alpha (x - x_0)(x- x_1) \cdots (x - x_n). Since p-q only has degree at most n, we must have \alpha=0 and thus p = q.
# X = @. cos( π*(0:N)/N )X =range(-1,1,N+1)functionℓ( j, x ) r =1;for n =0:Nif (n != j) r =r*(x - X[n+1]) / (X[j+1] - X[n+1])endendreturn r endanim =@animatefor j ∈0:N p = x ->ℓ(j, x)plot(p, -1, 1, ylims = (-5, 5), legend =false )scatter!( X, p.(X), primary =false, markersize =5, color="green", title = L"y = \ell_{j}(x)")endgif(anim, "Pictures/Lagrange interpolating polynomials.gif", fps =1)
Write down the polynomial of least degree interpolating f(x) = \sin(x) at the points 0, \frac{\pi}{2}, \pi
X =0:(π/2):πY =sin.( X )p = x ->-(4/π^2)*x*(x-π)plot( x ->sin(x) , -π/2, 3π/2, linestyle=:dash, label = L"y = \sin(x)")plot!( x ->p(x) , label ="polynomial interpolation" , lw =3 )scatter!( X, Y, primary =false, markersize =5, color="green")
Theorem.
Suppose f:[a,b]\to\mathbb R is n+1 times continuously differentiable and X = \{x_0 < \dots < x_n\}. Then, for all x \in [a,b] there exists \xi_x \in [\min \{x,x_0\} , \max \{x,x_n\}] such that
Here, g is an n+1 times continuously differentiable function with zeros at the n+2 distinct points x, x_0, \dots, x_n. As a result, by Rolle’s theorem (if a differentiable function is zero at its end points, there exists an interior point with zero derivative - the proof follows in the same way as in the proof of the mean value theorem) g' is zero at n+1 distinct points, g'' is zero at n distinct points, …., g^{(n)} is zero at 2 distinct points, and thus there exists \xi_x \in [\min \{x\} \cup X, \max \{x\}\cup X] such that g^{(n+1)}(\xi_x) = 0: